package com.trkj.base;

import android.app.ActionBar;
import android.app.Activity;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.WindowManager;
import android.widget.Toast;

import com.shamanland.fonticon.FontIconDrawable;
import com.trkj.base.utils.UserService;
import com.trkj.taoruiyun.R;
import com.trkj.usercenter.LoginActivity;
import com.trkj.widget.xiaomi.SystemBarTintManager;
import com.trkj.widget.xiaomi.XiaomiTint;

/**
 * Created by LiZanhong on 2015/06/15.
 */
public class BaseActivity extends Activity{
    protected SystemBarTintManager mTintManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initWindow();
        initActionBar();

        AppManager.getAppManager().addActivity(this);
    }

    protected void toast(String content){
        Toast.makeText(this, content, Toast.LENGTH_SHORT).show();
    }

    @Override
    protected void onResume() {
        super.onResume();
        if(!(this instanceof LoginActivity)) {
            UserService.getInstance(this).isLogin();
        }
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if(item.getItemId() == android.R.id.home){
            this.finish();
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);

        if(newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
        }else{
        }
    }

    /**
     * 初始化窗口
     */
    protected void initWindow(){
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            XiaomiTint.setTranslucentStatus(true, this);
            mTintManager = new SystemBarTintManager(this);
            XiaomiTint.setStatusBarDarkMode(false, this);
            mTintManager.setStatusBarTintEnabled(true);
            mTintManager.setStatusBarTintResource(R.color.orange);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }

    }

    /**
     * 初始化ActionBar
     */
    protected void initActionBar(){
        ActionBar actionBar = this.getActionBar();
        actionBar.setTitle(getCustomerTitle());
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowHomeEnabled(true);
        actionBar.setIcon(FontIconDrawable.inflate(this, R.xml.left_arrow));
    }

    protected String getCustomerTitle(){
        return null;
    };
}
